package org.cardcopier.file;

import java.io.File;
import java.io.FileFilter;
import java.util.Arrays;
import java.util.Map;

public class CaseSensitiveFileLocation extends AbstractFileLocation {

	private static class FileExtensionFilter implements FileFilter {
		
		private final String[] fileExtensions;
		
		public FileExtensionFilter(String[] fileExtensions) {
			this.fileExtensions = fileExtensions;
		}
		
		public boolean accept(File pathname) {
			for (String fileExtension : fileExtensions) {
				if (pathname.getName().endsWith(fileExtension)) {
					return true;
				}
			}
			return false;
		}

                public boolean equals(Object o) {
                    if (this == o) return true;
                    if (!(o instanceof FileExtensionFilter)) return false;
                    FileExtensionFilter f = (FileExtensionFilter)o;
                    return Arrays.equals(fileExtensions, f.fileExtensions);
                }
        }
	
	public CaseSensitiveFileLocation(File directory, String[] fileExtentions) {
		super(directory, new FileExtensionFilter(fileExtentions));
	}
		
	@Override
	protected void putFileInCache(Map<String, File> fileCache, File file) {
		fileCache.put(file.getName(), file);
	}
	
	@Override
	protected File getFileFromCache(Map<String, File> fileCache, String key) {
		return fileCache.get(key);
	}
		
}
